/**
 * @file foc.C
 * @brief 
 * @author LiWanglin (lwl510ll@163.com)
 * @version 1.0
 * @date 2024-08-18
 * 
 * @copyright Copyright (c) 2024  LiWanglin
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2024-08-18 <td>1.0     <td>wangh     <td>内容
 * </table>
 */


#include "foc.h"
#include <math.h>


void setPhaseVoltage(float Uq, float Ud, float angle_el)
{
    angle_el = _normalizeAngle(angle_el + zero_electric_angle);
    // 帕克逆变换
    Ualpha = -Uq * sin(angle_el);
    Ubeta = Uq * cos(angle_el);

    // 克拉克逆变换
    Ua = Ualpha + voltage_power_supply / 2;
    Ub = (sqrt(3) * Ubeta - Ualpha) / 2 + voltage_power_supply / 2;
    Uc = (-Ualpha - sqrt(3) * Ubeta) / 2 + voltage_power_supply / 2;
    setPwm(Ua, Ub, Uc);
}
